package jcpcotizaciones.Control;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import jcpcotizaciones.Modelo.TipoPapel;

public class ControlTipoPapel {

    private static List tipoPapel;
    private static Connection con;
    
    public static void listarTipoPapel() throws SQLException, Exception {
     ResultSet rs = null;
     PreparedStatement pst = null;
        tipoPapel = new LinkedList();
     try {
         ManejadorBaseDatos mbd=ManejadorBaseDatos.getInstancia();
         mbd.conectar();
         con=mbd.getConexion();
        pst = con.prepareStatement("select * from tipopapel");
        rs = pst.executeQuery();
        while(rs.next()) {
                tipoPapel.add(TipoPapel.load(rs));
        }
    } finally {
        if (rs != null) {
           rs.close();
       }
        if (pst != null) {
          pst.close();
       }
    }
}

        public static TipoPapel BuscarTipoPapel(String cod) throws SQLException{
         ResultSet rs = null;
         PreparedStatement pst = null;
         TipoPapel tp = null;
     try {
         ManejadorBaseDatos mbd=ManejadorBaseDatos.getInstancia();
         mbd.conectar();
         con=mbd.getConexion();
         pst = con.prepareStatement("select * from tipopapel where codtipopapel = ?");
         pst.setString(1, cod);

         rs = pst.executeQuery();
         while(rs.next()) {
             tp = TipoPapel.load(rs);
         }
    } finally {
         if (rs != null) {
            rs.close();
         }
         if (pst != null) {
           pst.close();
         }
          return tp;
    }
    }


    public static List getTipoPapel() {
        return tipoPapel;
    }

    /**
     * @param aTipoPapel the tipoPapel to set
     */
    public static void setTipoPapel(List aTipoPapel) {
        tipoPapel = aTipoPapel;
    }


}
